home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / hash.com / HASH.DOC < prev    next >
Encoding:
Text File  |  1989-09-26  |  1.8 KB  |  40 lines

  1. (*****************************************************************************)
  2.                    The Generic Hash Table (HTable) Object
  3.  
  4.                          written by : Eric C. Wentz
  5.  
  6.                      last mod date : September 26, 1989
  7.  
  8. (*****************************************************************************)
  9.  
  10. NOTE: These Units will not compile without several Units which can
  11.       be found in GENERI.ARC, available this library. Specifically,
  12.       Units GenDatum and FlexPntr.
  13.  
  14.  
  15. The HTable is a simple Generic Hash table, designed so that with very little
  16. effort it will be possible to Hash any data element desired.  As the HTable is
  17. defined as an Object, having multiple Hash Tables takes even less effort.
  18. Using the FlexStack unit, it would be very easy to create a stack of Hash
  19. tables, which (I am told..) would make compiler writing an easier task.  Be
  20. that as it may, more mundane Hashing can be achieved with greater ease than
  21. ever before, by using this Object. -- Enjoy!
  22.  
  23.  
  24.             (**************************************************)
  25.  
  26. The HTable uses an Externally-Chained Hash Table representation, and the
  27. most basic Hashing function I know of, yet gives surprisingly good results.
  28. The Hash function is:
  29.  
  30.          H := (Sum(Ord(CharactersInString))) MOD (LengthOfArray)
  31.  
  32. which returns 0..LengthOfArray-1. {Array is zero-based}
  33.  
  34. For some obscure mathematical reason, it turns out that the best lengths for
  35. such arrays are Prime numbers, so in Unit GenTable, the Constant MaxEntry is
  36. defined to be 23.  Feel free to redefine it to suit your application.  I
  37. suggest that you chose an appropriate prime such that the length trys to
  38. approximate 1/3 to 1/6 of the number of entries you expect to encounter. If
  39. you have no idea, redefine MaxEntry to be as large as you can.
  40.